Skip to content

Add the name resolver API #2285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: next
Choose a base branch
from

Conversation

arjan-bal
Copy link
Contributor

No description provided.

@arjan-bal
Copy link
Contributor Author

@dfawley @LucioFranco


/// The delay for the next retry, without the random jitter. Store as f64
/// to avoid rounding errors.
next_delay_secs: Mutex<f64>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need a mutex? It seems like we should generally only be accessing these serially.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct access is serial. The mutex is added to allow interior mutability. @easwars and I have a discussion about this on the group. The subchannel will also use backoffs and it will pass the backoff as an immutable value to keep the subchannel API clean. To get rid of the mutex we would need to use mutable acceptors in the trait definition and have the subchannel wrap the backoff in a mutex to get a mutable ref.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to extend the mut receiver out as far as we can. The mutex can go into the subchannel if that's what it needs to do. The backoff can express that it should not be called concurrently by making this a mutable receiver instead of an immutable one. The behavior of concurrent accesses would be undefined anyway.

Comment on lines +220 to +222
/// returns an empty endpoint list but a valid service config may set
/// to this to something like "no DNS entries found for <name>".
pub resolution_note: Option<String>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some requirement for using this? Like should it only be set if endpoints is empty? I.e. should we delete this and use an Err() from endpoints instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding, the resolution_note can be set when endpoints are present. The resolution note may say something like "the endpoints are stale" and the LB policy will add this message to the failure message if it fails to connect to the endpoints. Here is the code in CPP that sets a resolution node with a non-empty list of addresses.

pub resolution_note: Option<String>,
}

impl Default for ResolverUpdate {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be derived? Or no because of Result? If the latter, is there some way to partially derive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be derived directly due to the Result. We can't implement the Default trait for Result<T, E> because Result is from a foreign crate. We can wrap Result<Option<ServiceConfig>, String> in our own type, but that would add an extra layer for accessing the ServiceConfig/Entpoints etc.

I couldn't find a way to avoid listing the fields that already implement Default without adding a crate with macros. The closest think I found is using Default::default() as the value for such fields (e.g: attributes: Arc::default()). Using ..Default::default() at the end of the struct in the implementation of default() causes infinite recursion.

@arjan-bal arjan-bal requested a review from dfawley May 29, 2025 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants